package branch_and_price;

import ilog.concert.IloException;

import java.io.FileNotFoundException;
import java.util.ArrayList;

public class Master_Solve {
    public static void main(String[] args) throws FileNotFoundException, IloException {
        // 1.读取数据
        String name = 5 + "_" + 1;
        String data_file = "src/branch_and_price/data/TSP_instance_" + name + ".txt";
        System.out.println("<<<<<<<<<<<<<<<<<<<<<< TSP instance " + name + " >>>>>>>>>>>>>>>>>>>>>>");
        Data data = Input.Input_data(data_file);
        // data.show();

        // 2.计算初始解【计算一个初始的TSP路线】
        Greedy greedy = new Greedy(data);
        ArrayList<Integer> init_route = greedy.solve();
        Pool.showRoute(init_route);
        System.out.println("cost: "+data.cal_cost(init_route));

        // 3.构造路径池
        Pool pool = new Pool(data);
        pool.add_route(init_route);

        // 4.构造列生成的求解模型
        Master master = new Master(pool);
        master.construct();

        // 5.列生成算法求解
        CG cg = new CG(data);
        cg.solve(master);

        // 6.输出解
        master.show_sol();
        System.out.println("最后输出所有的解");
        for (int i = 0; i < pool.getRoute_Pool().size(); i++) {
            System.out.print("第"+i+"个：");
            Pool.showRoute(pool.getRoute_Pool().get(i));
            System.out.println();
        }
    }
}